package com.ruoyi.web.controller.system;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ArticleInfo;
import com.ruoyi.system.domain.Banner;
import com.ruoyi.system.domain.BannerSelectListDto;
import com.ruoyi.system.domain.vo.coopHan.PageCulvertApprovalVo;
import com.ruoyi.system.dto.article.PageArticleDto;
import com.ruoyi.system.dto.coopHan.PageCulvertDto;
import com.ruoyi.system.service.IArticleInfoService;
import com.ruoyi.system.service.IAssociationClapCulvertService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.rmi.ServerException;
import java.util.List;

/**
 * <p>
 * 文章管理 前端控制器
 * </p>
 *
 * @author yanfu
 * @since 2024-04-07
 */
@RestController
@RequestMapping("/article/info")
@RequiredArgsConstructor
@Api(tags = {"文章管理API"})
public class ArticleInfoController {

    //        IArticleInfoService
    @Autowired
    private IArticleInfoService service;

    @PostMapping("/page")
    @ApiOperation(value = "文章管理分页列表")
    public AjaxResult<Page<ArticleInfo>> getPage(@RequestBody PageArticleDto dto) {
        Page<ArticleInfo> articleInfoPage = service.pageCulvert(dto);
        return AjaxResult.success(articleInfoPage);
    }

    @DeleteMapping("/del")
    @ApiOperation(value = "文章删除")
    public AjaxResult delete(@RequestParam List<Long> ids) {
        service.delete(ids);
        return AjaxResult.success("删除成功");
    }

    @PostMapping("/add")
    @ResponseBody
    @ApiOperation(value = "添加文章")
    public AjaxResult addSave(@RequestBody ArticleInfo addDto) {
        service.save(addDto);
        return AjaxResult.success("添加成功");
    }


    @PostMapping("/update")
    @ResponseBody
    @ApiOperation(value = "编辑文章")
    public AjaxResult update(@RequestBody ArticleInfo addDto) {
        service.update(addDto);
        return AjaxResult.success("编辑成功");
    }

    @GetMapping("/selectById")
    @ResponseBody
    @ApiOperation(value = "查看文章详情")
    public AjaxResult<ArticleInfo> selectById(@RequestParam Long id) {
        ArticleInfo articleInfo = service.selectById(id);
        return AjaxResult.success(articleInfo);
    }

    @GetMapping("/selectByList")
    @ResponseBody
    @ApiOperation(value = "轮播图列表接口")
    public AjaxResult<List<ArticleInfo>> selectById() {
        List<ArticleInfo> articleInfos = service.selectByList();
        return AjaxResult.success(articleInfos);
    }

}

